package com.liaojp.cmsweb.controller;

import com.liaojp.cmsweb.Result.AjaxResult;
import com.liaojp.cmsweb.httpParam.user.LoginParam;
import com.liaojp.cmsweb.httpParam.user.RegisterParam;
import com.liaojp.cmsweb.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class UserController {
    private static final Logger log = LoggerFactory.getLogger(UserController.class);
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }


    /**
     * 登录接口
     * @param loginParam 登录参数
     * @return 响应
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginParam loginParam){
        log.info("loginParam:{}", loginParam);

        return userService.login(loginParam);
    }

    /**
     * 普通用户注册。角色-employee
     * @param registerParam 注册参数
     * @return 响应
     */
    @PostMapping("/register")
    public AjaxResult register(@RequestBody RegisterParam registerParam){
        log.info("registerParam:{}", registerParam);
        return userService.register(registerParam);
    }
}
